//
// Description: priority_queue 优先级队列
// Created by Loading on 2021/4/18.
//

#include <bits/stdc++.h>

using namespace std;

int main() {
    //优先级排序方式为默认，less<int>，降序排列
    priority_queue<int> q;
    //等同于 priority_queue<int, vector<int>, less<>> q

    q.push(3);
    q.push(1);
    q.push(4);
    q.push(2);

    while (!q.empty()) {
        cout << q.top() << " ";
        q.pop();
    }
    cout << endl;

    //优先级为升序
    priority_queue<int, vector<int>, greater<>> q1;
    q1.push(3);
    q1.push(1);
    q1.push(4);
    q1.push(2);

    while (!q1.empty()) {
        cout << q1.top() << " ";
        q1.pop();
    }
    cout << endl;

    //用pair做优先级队列中的元素
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> qp;
    pair<int, int> p1(1, 2);
    pair<int, int> p2(1, 3);
    pair<int, int> p3(2, 5);
    qp.push(p1);
    qp.push(p2);
    qp.push(p3);

    while (!qp.empty()){
        cout << qp.top().first << " " << qp.top().second << endl;
        qp.pop();
    }
}